package svc

import (
	"zindle/internal/config"
	"zindle/internal/middleware"
	"zindle/internal/model"

	"github.com/zeromicro/go-zero/core/stores/sqlx"
	"github.com/zeromicro/go-zero/rest"
)

type ServiceContext struct {
	Config                 config.Config
	CheckLogin             rest.Middleware
	SystemUserModel        model.SystemUserModel
	SystemMenusModel       model.SystemMenusModel
	SystemApisModel        model.SystemApisModel
	SystemRolesModel       model.SystemRolesModel
	SystemDepartmentsModel model.SystemDepartmentsModel
	SystemRoleMenusModel   model.SystemRoleMenusModel
	SystemRoleApisModel    model.SystemRoleApisModel
	BooksModel             model.BooksModel
	BookOrdersModel        model.BookOrdersModel
	ReadersModel           model.ReadersModel
	VerifyCodesModel       model.VerifyCodesModel
}

func NewServiceContext(c config.Config) *ServiceContext {
	conn := sqlx.NewMysql(c.Mysql.DataSource)
	return &ServiceContext{
		Config:     c,
		CheckLogin: middleware.NewCheckLoginMiddleware(c.Mysql.DataSource).Handle,

		SystemUserModel:        model.NewSystemUserModel(conn, c.CacheRedis),
		SystemMenusModel:       model.NewSystemMenusModel(conn, c.CacheRedis),
		SystemApisModel:        model.NewSystemApisModel(conn, c.CacheRedis),
		SystemRolesModel:       model.NewSystemRolesModel(conn, c.CacheRedis),
		SystemDepartmentsModel: model.NewSystemDepartmentsModel(conn, c.CacheRedis),
		SystemRoleMenusModel:   model.NewSystemRoleMenusModel(conn, c.CacheRedis),
		SystemRoleApisModel:    model.NewSystemRoleApisModel(conn, c.CacheRedis),
		BooksModel:             model.NewBooksModel(conn, c.CacheRedis),
		BookOrdersModel:        model.NewBookOrdersModel(conn, c.CacheRedis),
		ReadersModel:           model.NewReadersModel(conn, c.CacheRedis),
		VerifyCodesModel:       model.NewVerifyCodesModel(conn, c.CacheRedis),
	}
}
